package com.xuzimian.globaldemo.spring.springwebflux.route;

import com.xuzimian.globaldemo.spring.springwebflux.handler.UserHandler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.ServerResponse;

import static org.springframework.http.MediaType.APPLICATION_JSON;
import static org.springframework.web.reactive.function.server.RouterFunctions.route;
import static org.springframework.web.reactive.function.server.RequestPredicates.GET;
import static org.springframework.web.reactive.function.server.RequestPredicates.*;

/**
 * @program: spring-webflux
 * @description:
 * @author: xzm
 * @create: 2019-04-28 17:19
 **/
@Configuration
public class RoutingConfiguration {

    @Bean
    public RouterFunction<ServerResponse> monoRouterFunction(UserHandler userHandler) {
            return route(GET("/user").and(accept(APPLICATION_JSON)), userHandler::getUser)
            .andRoute(GET("/user/{customers}").and(accept(APPLICATION_JSON)), userHandler::getUserCustomers);
    }
}